﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwPrijenosRadnogNalogaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwPrijenosRadnogNalogaProviderBaseCore : EntityViewProviderBase<VwPrijenosRadnogNaloga>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwPrijenosRadnogNaloga&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwPrijenosRadnogNaloga&gt;"/></returns>
		protected static VList&lt;VwPrijenosRadnogNaloga&gt; Fill(DataSet dataSet, VList<VwPrijenosRadnogNaloga> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwPrijenosRadnogNaloga>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwPrijenosRadnogNaloga&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwPrijenosRadnogNaloga>"/></returns>
		protected static VList&lt;VwPrijenosRadnogNaloga&gt; Fill(DataTable dataTable, VList<VwPrijenosRadnogNaloga> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwPrijenosRadnogNaloga c = new VwPrijenosRadnogNaloga();
					c.IDDokument = (Convert.IsDBNull(row["IDDokument"]))?(int)0:(System.Int32)row["IDDokument"];
					c.RedBr = (Convert.IsDBNull(row["RedBr"]))?(int)0:(System.Int32?)row["RedBr"];
					c.Oznaka = (Convert.IsDBNull(row["Oznaka"]))?string.Empty:(System.String)row["Oznaka"];
					c.TipSkraceniNaziv = (Convert.IsDBNull(row["TipSkraceniNaziv"]))?string.Empty:(System.String)row["TipSkraceniNaziv"];
					c.TipNaziv = (Convert.IsDBNull(row["TipNaziv"]))?string.Empty:(System.String)row["TipNaziv"];
					c.IDDokTip = (Convert.IsDBNull(row["IDDokTip"]))?(int)0:(System.Int32)row["IDDokTip"];
					c.Klijent = (Convert.IsDBNull(row["Klijent"]))?string.Empty:(System.String)row["Klijent"];
					c.MB = (Convert.IsDBNull(row["MB"]))?string.Empty:(System.String)row["MB"];
					c.DjelatnikIme = (Convert.IsDBNull(row["DjelatnikIme"]))?string.Empty:(System.String)row["DjelatnikIme"];
					c.DjelatnikUser = (Convert.IsDBNull(row["DjelatnikUser"]))?string.Empty:(System.String)row["DjelatnikUser"];
					c.SkladisteSifraOd = (Convert.IsDBNull(row["SkladisteSifraOd"]))?string.Empty:(System.String)row["SkladisteSifraOd"];
					c.SkladisteOd = (Convert.IsDBNull(row["SkladisteOd"]))?string.Empty:(System.String)row["SkladisteOd"];
					c.Datum = (Convert.IsDBNull(row["Datum"]))?DateTime.MinValue:(System.DateTime)row["Datum"];
					c.IDTip = (Convert.IsDBNull(row["IDTip"]))?(int)0:(System.Int32)row["IDTip"];
					c.Naziv = (Convert.IsDBNull(row["Naziv"]))?string.Empty:(System.String)row["Naziv"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwPrijenosRadnogNaloga&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwPrijenosRadnogNaloga&gt;"/></returns>
		protected VList<VwPrijenosRadnogNaloga> Fill(IDataReader reader, VList<VwPrijenosRadnogNaloga> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwPrijenosRadnogNaloga entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwPrijenosRadnogNaloga>("VwPrijenosRadnogNaloga",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwPrijenosRadnogNaloga();
					}
					entity.IDDokument = (System.Int32)reader["IDDokument"];
					//entity.IDDokument = (Convert.IsDBNull(reader["IDDokument"]))?(int)0:(System.Int32)reader["IDDokument"];
					entity.RedBr = reader.IsDBNull(reader.GetOrdinal("RedBr")) ? null : (System.Int32?)reader["RedBr"];
					//entity.RedBr = (Convert.IsDBNull(reader["RedBr"]))?(int)0:(System.Int32?)reader["RedBr"];
					entity.Oznaka = (System.String)reader["Oznaka"];
					//entity.Oznaka = (Convert.IsDBNull(reader["Oznaka"]))?string.Empty:(System.String)reader["Oznaka"];
					entity.TipSkraceniNaziv = reader.IsDBNull(reader.GetOrdinal("TipSkraceniNaziv")) ? null : (System.String)reader["TipSkraceniNaziv"];
					//entity.TipSkraceniNaziv = (Convert.IsDBNull(reader["TipSkraceniNaziv"]))?string.Empty:(System.String)reader["TipSkraceniNaziv"];
					entity.TipNaziv = reader.IsDBNull(reader.GetOrdinal("TipNaziv")) ? null : (System.String)reader["TipNaziv"];
					//entity.TipNaziv = (Convert.IsDBNull(reader["TipNaziv"]))?string.Empty:(System.String)reader["TipNaziv"];
					entity.IDDokTip = (System.Int32)reader["IDDokTip"];
					//entity.IDDokTip = (Convert.IsDBNull(reader["IDDokTip"]))?(int)0:(System.Int32)reader["IDDokTip"];
					entity.Klijent = reader.IsDBNull(reader.GetOrdinal("Klijent")) ? null : (System.String)reader["Klijent"];
					//entity.Klijent = (Convert.IsDBNull(reader["Klijent"]))?string.Empty:(System.String)reader["Klijent"];
					entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
					//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
					entity.DjelatnikIme = (System.String)reader["DjelatnikIme"];
					//entity.DjelatnikIme = (Convert.IsDBNull(reader["DjelatnikIme"]))?string.Empty:(System.String)reader["DjelatnikIme"];
					entity.DjelatnikUser = (System.String)reader["DjelatnikUser"];
					//entity.DjelatnikUser = (Convert.IsDBNull(reader["DjelatnikUser"]))?string.Empty:(System.String)reader["DjelatnikUser"];
					entity.SkladisteSifraOd = (System.String)reader["SkladisteSifraOd"];
					//entity.SkladisteSifraOd = (Convert.IsDBNull(reader["SkladisteSifraOd"]))?string.Empty:(System.String)reader["SkladisteSifraOd"];
					entity.SkladisteOd = (System.String)reader["SkladisteOd"];
					//entity.SkladisteOd = (Convert.IsDBNull(reader["SkladisteOd"]))?string.Empty:(System.String)reader["SkladisteOd"];
					entity.Datum = (System.DateTime)reader["Datum"];
					//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
					entity.IDTip = (System.Int32)reader["IDTip"];
					//entity.IDTip = (Convert.IsDBNull(reader["IDTip"]))?(int)0:(System.Int32)reader["IDTip"];
					entity.Naziv = (System.String)reader["Naziv"];
					//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwPrijenosRadnogNaloga"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwPrijenosRadnogNaloga"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwPrijenosRadnogNaloga entity)
		{
			reader.Read();
			entity.IDDokument = (System.Int32)reader["IDDokument"];
			//entity.IDDokument = (Convert.IsDBNull(reader["IDDokument"]))?(int)0:(System.Int32)reader["IDDokument"];
			entity.RedBr = reader.IsDBNull(reader.GetOrdinal("RedBr")) ? null : (System.Int32?)reader["RedBr"];
			//entity.RedBr = (Convert.IsDBNull(reader["RedBr"]))?(int)0:(System.Int32?)reader["RedBr"];
			entity.Oznaka = (System.String)reader["Oznaka"];
			//entity.Oznaka = (Convert.IsDBNull(reader["Oznaka"]))?string.Empty:(System.String)reader["Oznaka"];
			entity.TipSkraceniNaziv = reader.IsDBNull(reader.GetOrdinal("TipSkraceniNaziv")) ? null : (System.String)reader["TipSkraceniNaziv"];
			//entity.TipSkraceniNaziv = (Convert.IsDBNull(reader["TipSkraceniNaziv"]))?string.Empty:(System.String)reader["TipSkraceniNaziv"];
			entity.TipNaziv = reader.IsDBNull(reader.GetOrdinal("TipNaziv")) ? null : (System.String)reader["TipNaziv"];
			//entity.TipNaziv = (Convert.IsDBNull(reader["TipNaziv"]))?string.Empty:(System.String)reader["TipNaziv"];
			entity.IDDokTip = (System.Int32)reader["IDDokTip"];
			//entity.IDDokTip = (Convert.IsDBNull(reader["IDDokTip"]))?(int)0:(System.Int32)reader["IDDokTip"];
			entity.Klijent = reader.IsDBNull(reader.GetOrdinal("Klijent")) ? null : (System.String)reader["Klijent"];
			//entity.Klijent = (Convert.IsDBNull(reader["Klijent"]))?string.Empty:(System.String)reader["Klijent"];
			entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
			//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
			entity.DjelatnikIme = (System.String)reader["DjelatnikIme"];
			//entity.DjelatnikIme = (Convert.IsDBNull(reader["DjelatnikIme"]))?string.Empty:(System.String)reader["DjelatnikIme"];
			entity.DjelatnikUser = (System.String)reader["DjelatnikUser"];
			//entity.DjelatnikUser = (Convert.IsDBNull(reader["DjelatnikUser"]))?string.Empty:(System.String)reader["DjelatnikUser"];
			entity.SkladisteSifraOd = (System.String)reader["SkladisteSifraOd"];
			//entity.SkladisteSifraOd = (Convert.IsDBNull(reader["SkladisteSifraOd"]))?string.Empty:(System.String)reader["SkladisteSifraOd"];
			entity.SkladisteOd = (System.String)reader["SkladisteOd"];
			//entity.SkladisteOd = (Convert.IsDBNull(reader["SkladisteOd"]))?string.Empty:(System.String)reader["SkladisteOd"];
			entity.Datum = (System.DateTime)reader["Datum"];
			//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
			entity.IDTip = (System.Int32)reader["IDTip"];
			//entity.IDTip = (Convert.IsDBNull(reader["IDTip"]))?(int)0:(System.Int32)reader["IDTip"];
			entity.Naziv = (System.String)reader["Naziv"];
			//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwPrijenosRadnogNaloga"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwPrijenosRadnogNaloga"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwPrijenosRadnogNaloga entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDDokument = (Convert.IsDBNull(dataRow["IDDokument"]))?(int)0:(System.Int32)dataRow["IDDokument"];
			entity.RedBr = (Convert.IsDBNull(dataRow["RedBr"]))?(int)0:(System.Int32?)dataRow["RedBr"];
			entity.Oznaka = (Convert.IsDBNull(dataRow["Oznaka"]))?string.Empty:(System.String)dataRow["Oznaka"];
			entity.TipSkraceniNaziv = (Convert.IsDBNull(dataRow["TipSkraceniNaziv"]))?string.Empty:(System.String)dataRow["TipSkraceniNaziv"];
			entity.TipNaziv = (Convert.IsDBNull(dataRow["TipNaziv"]))?string.Empty:(System.String)dataRow["TipNaziv"];
			entity.IDDokTip = (Convert.IsDBNull(dataRow["IDDokTip"]))?(int)0:(System.Int32)dataRow["IDDokTip"];
			entity.Klijent = (Convert.IsDBNull(dataRow["Klijent"]))?string.Empty:(System.String)dataRow["Klijent"];
			entity.MB = (Convert.IsDBNull(dataRow["MB"]))?string.Empty:(System.String)dataRow["MB"];
			entity.DjelatnikIme = (Convert.IsDBNull(dataRow["DjelatnikIme"]))?string.Empty:(System.String)dataRow["DjelatnikIme"];
			entity.DjelatnikUser = (Convert.IsDBNull(dataRow["DjelatnikUser"]))?string.Empty:(System.String)dataRow["DjelatnikUser"];
			entity.SkladisteSifraOd = (Convert.IsDBNull(dataRow["SkladisteSifraOd"]))?string.Empty:(System.String)dataRow["SkladisteSifraOd"];
			entity.SkladisteOd = (Convert.IsDBNull(dataRow["SkladisteOd"]))?string.Empty:(System.String)dataRow["SkladisteOd"];
			entity.Datum = (Convert.IsDBNull(dataRow["Datum"]))?DateTime.MinValue:(System.DateTime)dataRow["Datum"];
			entity.IDTip = (Convert.IsDBNull(dataRow["IDTip"]))?(int)0:(System.Int32)dataRow["IDTip"];
			entity.Naziv = (Convert.IsDBNull(dataRow["Naziv"]))?string.Empty:(System.String)dataRow["Naziv"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwPrijenosRadnogNalogaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPrijenosRadnogNaloga"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPrijenosRadnogNalogaFilterBuilder : SqlFilterBuilder<VwPrijenosRadnogNalogaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaFilterBuilder class.
		/// </summary>
		public VwPrijenosRadnogNalogaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwPrijenosRadnogNalogaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwPrijenosRadnogNalogaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwPrijenosRadnogNalogaFilterBuilder

	#region VwPrijenosRadnogNalogaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPrijenosRadnogNaloga"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPrijenosRadnogNalogaParameterBuilder : ParameterizedSqlFilterBuilder<VwPrijenosRadnogNalogaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaParameterBuilder class.
		/// </summary>
		public VwPrijenosRadnogNalogaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwPrijenosRadnogNalogaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwPrijenosRadnogNalogaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwPrijenosRadnogNalogaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwPrijenosRadnogNalogaParameterBuilder
} // end namespace
